package cn.tedu.zhwy.workspase.service.impl;

import cn.tedu.zhwy.base.response.JsonResult;
import cn.tedu.zhwy.workspase.mapper.WorkSpaceMapper;
import cn.tedu.zhwy.workspase.pojo.dto.LandlordParam;
import cn.tedu.zhwy.workspase.pojo.entity.Landlord;
import cn.tedu.zhwy.workspase.pojo.vo.LamdlordVO;
import cn.tedu.zhwy.workspase.service.WorkSpaceService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Slf4j
@Service
public class WorkSpaceServiceImpl implements WorkSpaceService {
    @Autowired
    private WorkSpaceMapper workSpaceMapper;
    @Override
    public void save(LandlordParam landlordParam) {
        log.debug("landlordParam  S:{}",landlordParam);
        Landlord landlord = new Landlord();
        BeanUtils.copyProperties(landlordParam,landlord);
        if (landlord.getLid()==null){

            landlord.setLtime(new Date());
            workSpaceMapper.save(landlord);
        }else {
            landlord.setLtime(new Date());
            workSpaceMapper.update(landlord);
        }

    }

    @Override
    public List<LamdlordVO> select(LandlordParam landlordParam) {
        log.debug("landlordParam  S:{}",landlordParam);
        List<LamdlordVO> list = workSpaceMapper.select(landlordParam);
        return list;
    }

    @Override
    public void delete(Integer lid) {
        log.debug("lid  S:{}",lid);
        workSpaceMapper.detele(lid);
    }

}
